#ifndef MYTHREADFORSERIAL_H
#define MYTHREADFORSERIAL_H

#include <QThread>
class QSerialPort;
class QSharedMemory;
class SubWidget_Serial;
class QTimer;

class MyThreadForSerial:public QThread
{
public:
    MyThreadForSerial();
    //读写 共享内存
    void SharedMemory_write();
    void SharedMemory_read();
    void SharedMemory_readNative();  //读windows内存数据
    //数据处理
    double receive_message(QByteArray d);
    //返回封装在内部的SerialPort对象
    const SubWidget_Serial& get()const;
    //让串口通信界面显示
    void show();
private:
    class DataFrame;
    double deal_humidity(DataFrame datafrm);
protected:
    void run() override;

private:
    //子线程自己进行串口初始化和连接
    void Serial_init();
private:
    class DataFrame
    {
    public:
        DataFrame();
        //增
        void append(char d);
        //删
        void clear();
        //改
        char& operator [](std::size_t index);
        const char& operator [](std::size_t index) const;
        //查
        void print();
        //返回数据尺寸
        std::size_t size();
    private:
        std::vector<char> datas;
    };

private:
    QSerialPort *m_SerialPort;
    QSharedMemory *m_SharedMemory_write;
    QSharedMemory *m_SharedMemory_read;
    DataFrame m_datafrm;
    SubWidget_Serial *m_Serial;
    QTimer *timer;
signals:
    //这里 打算返回当前温度、湿度、电机转速等等
};

#endif // MYTHREADFORSERIAL_H
